package com.spzx.test1.t8;
/*
    并非全力
*/

import org.apache.commons.lang3.RandomUtils;

import java.util.concurrent.TimeUnit;

public class test1 {
    public static void main(String[] args) {

        Lip lip = new Lip();
        Mirror mirror = new Mirror();


        new Thread(() -> {
            synchronized (lip) {
                System.out.println(Thread.currentThread().getName() + "拿到了口红，在找镜子");

                try {
                    TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1,5));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                synchronized (mirror) {
                    System.out.println(Thread.currentThread().getName() + "拿到镜子，在化妆");
                    try {
                        TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1,5));
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println(Thread.currentThread().getName() + "化妆结束sb");
                }
            }
        }, "小红").start();


        new Thread(() -> {
            synchronized (mirror) {
                    System.out.println(Thread.currentThread().getName() + "拿到了镜子，在找口红");

                    try {
                        TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1,5));
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                    synchronized (lip) {
                        System.out.println(Thread.currentThread().getName() + "拿到口红，在化妆");
                        try {
                            TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1,5));
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        System.out.println(Thread.currentThread().getName() + "化妆结束sb");
                    }
                }
            },"小蓝").start();
        }
    }
